package com.springcloud.resttemplate.ribbon.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Desc:
 * @Date: 2020-06-25
 * @Version:v1.0
 */
@Service
public class RibbonService {

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "sayHelloFallback")
    public String sayHello(String name) {
        return restTemplate.getForObject("http://springcloud-eureka-client/hello?name=" + name, String.class);
    }

    public String sayHelloFallback(String name) {
        return "hello, " + name + ", sorry, ribbon client error";
    }
}
